package com.penjin.android.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.penjin.android.R;
import com.penjin.android.domain.KaoqinLeaveData;
import com.penjin.android.domain.KaoqinPersonData;
import com.penjin.android.domain.KaoqinTiaoxiuData;
import com.penjin.android.domain.PenjinDepartment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fengjw on 2016/4/9.
 */
public class ListViewAdapter extends BaseAdapter {
    //activity nosign
    List<PenjinDepartment> departmentList;
    List<List<KaoqinPersonData>> staffLists;
    Context mContext;
    List<KaoqinPersonData> staffList = new ArrayList<>();



    //activity tiaoxiu
    List<KaoqinLeaveData> kaoqinLeaveDataList = new ArrayList<>();
    List<KaoqinTiaoxiuData> kaoqinTiaoxiuDataList = new ArrayList<>();
    private String name1,name2;


    public ListViewAdapter(Context context ){
        this.mContext = context;
    }



    public void setData(List<PenjinDepartment> list, List<List<KaoqinPersonData>> lists){
        this.departmentList=list;
        this.staffLists=lists;
    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(departmentList.size() == 0){
            Log.d("fengjw","departmentList size() : "+departmentList.size());
            return 0;
        }else{
        return departmentList.size();
     }
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return departmentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ListHolder holder=null;

        if(null == holder){
            holder=new ListHolder();

            convertView= LayoutInflater.from(mContext).inflate(R.layout.listview_kaoqinnosign_item, null);

            holder.name=(TextView) convertView.findViewById(R.id.textView1);
            holder.gridview=(InnerGridView) convertView.findViewById(R.id.gridview);
            holder.head_item=(LinearLayout) convertView.findViewById(R.id.head_item);

            convertView.setTag(holder);
        }else{
            holder=(ListHolder) convertView.getTag();
        }

        holder.name.setText(departmentList.get(position).getDepartmentName());

        staffList = staffLists.get(position);
        GridViewAdapter gridViewAdapter= new GridViewAdapter(mContext , staffList);
        holder.gridview.setAdapter(gridViewAdapter);

        return convertView;
    }

    public static class ListHolder{
        TextView name;
        InnerGridView gridview;
        LinearLayout head_item;
    }

}
